<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<meta charset="utf-8">
<head>
    <link type="text/css" href="${pageContext.request.contextPath}/css/login.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/scripts/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        $(function () {
            $("[type=button]").click(function () {
                $.ajax({
                    type:"get",
                    url:"/userServlet",
                    data:{
                        "doType":"doQuery",
                        "type":"login",
                        "email":$("[name=email]").val(),
                        "password":$("[type=password]").val()
                    },
                    success:function (data) {
                        if(data[0]==1){
                            alert("请将email和密码输入完整！")
                        }else if(data[0]==2){
                            var jurisdiction=data[1];
                            if(jurisdiction==1){
                                alert("恭喜你登录成功！点击确定3秒钟之后自动跳转到首页。")
                                window.setTimeout(function(){
                                    window.location.href="${pageContext.request.contextPath}/index.jsp";
                                },3000);
                            }else if(jurisdiction==2){
                                alert("恭喜你登录成功！点击确定3秒钟之后自动跳转到后台管理系统。")
                                window.setTimeout(function(){
                                    window.location.href="${pageContext.request.contextPath}/admin/admin.jsp";
                                },3000);
                            }
                        }else if(data[0]==3){
                            alert("该email还未注册！")
                        }else if(data[0]==4){
                            alert("密码错误！")
                        }
                    }
                })
            })
        })
    </script>
   <title>登录</title>
</head>
<body >
    <div id="dangdang">
        <p><a href="${pageContext.request.contextPath}/index.jsp"><img src="${pageContext.request.contextPath}/images/dangdang.png"></a></p>
    </div>
    <div id="container" align="center">

        <div id="login">
            <form action="return false" method="post">
                <table>
                    <tr>
                        <td align="right">请输入Email地址：</td>
                        <td><input type="text" name="email"></td>
                    </tr>
                    <tr>
                        <td align="right">密码：</td>
                        <td><input type="password" ></td>
                    </tr>
                    <td></td>
                    <td><input type="button" value="登录"></td>
                    </tr>
                </table>
            </form>
            <span><a href="${pageContext.request.contextPath}/register.jsp">创建账户    》</a></span>
        </div>
    </div>
</body>
</html>
